package com.example.quartz.consumer.sms;

import com.example.quartz.annotation.RestMappingController;
import com.example.quartz.common.base.BaseController;
import com.example.quartz.common.base.ResponseResultBean;
import com.example.quartz.module.sms.QuartzTask;
import com.example.quartz.provider.sms.mapper.QuartzTaskMapper;
import com.example.quartz.provider.sms.service.QuartzTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.quartz.SchedulerException;
import org.springframework.web.bind.annotation.PostMapping;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author: wlp
 * @description: 描述：定时任务  前端控制器 定时任务时间表达式在线生成： http://www.bejson.com/othertools/cron/
 * @projectName: QuartzTaskController
 * @date: 2019/10/11
 * @version: V1.0.0
 */
@Api(tags = "定时任务模块API", description = "定时任务模块API")
@RestMappingController("quartzTask")
@Slf4j
public class QuartzTaskController extends BaseController<QuartzTask, QuartzTaskMapper> {

    @Resource
    private QuartzTaskService quartzTaskService;

    @PostMapping("startJob")
    @ApiOperation(value = "测试运行定时任务", httpMethod = "POST")
    public ResponseResultBean startJob() {
        //**10秒执行一次
        String cron = "*/10 * * * * ?";
        QuartzTask quartzTask = QuartzTask.builder()
                .quartzStatus(0)
                .params("大吉大利，今晚吃鸡")
                .quartzCron(cron)
                .quartzName("测试运行定时任务")
                .createTime(new Date())
                .createUserId(1L)
                .quartzType(1)
                .targetBean("reportTask")
                .targetMethod("testTask")
                .delFlag(false)
                .build();
        quartzTaskService.insert(quartzTask);
        return ResponseResultBean.success();
    }
}
